var awx = require("./awx")

let api = {
  login: async function () {
    try {
      let callResult = await awx.cloud.callFunction({
        name: 'login',
        data: {},
      });
      console.log(callResult);
      return Promise.resolve(callResult.result);
    } catch (err) {
      console.log('login catch exception, err=' + err);
      return Promise.reject('exception ' + err);
    };
  },

  getBlessRoundInfo: async function () {
    try {
      let callResult = await awx.cloud.callFunction({
        name: 'bless',
        data: {
          action: 'roundInfo',
        },
      });
      console.log(callResult);
      return Promise.resolve(callResult.result);
    } catch (err) {
      console.log('round info catch exception, err=' + err);
      return Promise.reject('exception ' + err);
    };
  },

  postBlessRoundResult: async function (activityId, words) {
    try {
      let callResult = await awx.cloud.callFunction({
        name: 'bless',
        data: {
          action: 'postRoundResult',
          activity: activityId,
          words: words,
        },
      });
      console.log(callResult);
      return Promise.resolve(callResult.result);
    } catch (err) {
      console.log('post round catch exception, err=' + err);
      return Promise.reject('exception ' + err);
    };
  },
}

module.exports = api;